package com.qhw.jdbc;

import javax.sound.midi.Soundbank;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class AppJdbcInsert {
    public static void main(String[] args) throws Exception {
        Class.forName("com.mysql.cj.jdbc.Driver");
        String url = "jdbc:mysql://localhost:3306/test?useSSL=false";
        String name = "root";
        String password = "password";
        Connection connection = DriverManager.getConnection(url, name, password);
        Statement statement = connection.createStatement();
        String sql ="insert into `user` (`username`,`password`)values('Jason',MD5(666))";

        //若语句statement.executeUpdate(sql)成功执行，则该语句返回int值并且为1
        //除了查询语句用statement.executeQuery(sql)，增删改都用statement.executeUpdate(sql)

        int i = statement.executeUpdate(sql);  //若插入成功返回1
        if (i>0)   System.out.println("插入成功！");
    }
}
